package com.cloudkinto.controller.analysis;

import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.service.analysis.AnalysisService;
import com.cloudkinto.service.analysis.vo.AnalysisReq;
import com.cloudkinto.service.analysis.vo.StockAgeReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhujiale
 * @description
 * @date 2022/11/30
 */
@RestController
@Api(tags = "客户统计模块")
@RequestMapping("api/analysis")
public class AnalysisController extends BaseController {
    @Autowired
    private AnalysisService service;

    @UserSessionRequired
    @GetMapping("/init")
    @ApiOperation(value = "初始化", notes = "初始化")
    public Object init(HttpServletRequest request) {
        String[] storageIdList = request.getParameterValues("storageIdList");
        return service.init(getCompanyId(), storageIdList);
    }

    @UserSessionRequired
    @GetMapping("/customerAnalysis")
    @ApiOperation(value = "客户统计", notes = "客户统计")
    public Object customerAnalysis() {
        return service.customerAnalysis();
    }

    @UserSessionRequired
    @PostMapping("/storageSituation")
    @ApiOperation(value = "仓库概况", notes = "仓库概况")
    public Object storageSituation(@RequestBody @Validated AnalysisReq req) {
        return service.storageSituation(req, getCompanyId());
    }

    @UserSessionRequired
    @PostMapping("/stockAgeAnalysis")
    @ApiOperation(value = "库龄统计", notes = "库龄统计")
    public Object stockAgeAnalysis(@RequestBody @Validated StockAgeReq req) {
        return service.stockAgeAnalysis(req, getCompanyId());
    }


}
